package com.wx;


import com.wx.dao.SmbmsUserDao;
import com.wx.entry.SmbmsUser;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MainTest {
    public static void main(String[] args) {
        String config = "mybatis-config.xml";
        try {
            //读取配置文件
            InputStream inputStream = Resources.getResourceAsStream(config);
            //创建工厂建造者
            SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();
            //通过工厂建造者，创建工厂
            SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(inputStream);
            //通过工厂，创建sqlsession
            SqlSession sqlSession = sqlSessionFactory.openSession();
            //通过sqlsession 获得mapper 接口对象
            SmbmsUserDao smbmsUserDao =  sqlSession.getMapper(SmbmsUserDao.class);
            //调用接口方法。
            SmbmsUser smbmsUser= smbmsUserDao.getSmbmsUserByUserCode("admin");
            System.out.println(smbmsUser);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
